<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="com.asaga.tools.*, java.util.*, java.io.*, java.net.*"%>

<!-- IMPORT from JavaMail API -->
<%@page import="javax.mail.*, javax.mail.internet.*, javax.activation.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<% 
    RegistrationHandler rh = (RegistrationHandler)session.getAttribute("registration_handler");
    String fname = rh.getName();
    String message = (String)session.getAttribute("errorMessage");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/autism292.css" />
        <title>Thank You for Registering</title>
    </head>
    <body>
         <div id="pagewidth" >
            <div id="header" >
                <center>
                    <img src="images/ASAGGC_Logo_Banner.gif" 
                         alt="Autism Society of America - Greater Georgia Chapter" />
                </center>
            </div>
            <div id="twocols" class="clearfix">
                <div id="maincol">
                  <p>
                     Registration Successfull! 
                  </p>
                  <p>
                    Thank you, <%= fname %> for registering.  You should receive an email
                    confirming your registration shortly.  Please return to the main <a href="index.jsp">website</a>.
                  </p>  
                  <%=message %> <br />
                  
                  <!-- START Welcome Email Module -->
                  <%

				        // SMTP server address
                        String SMTP_HOST = "localhost";

						// Sender's email information
                        String mailFrom = "administrator@localhost";

						// Get recipient's email address from RegistrationHandler.java
                        String mailTo = rh.getEmail();

						// Contents of email
                        String mailtitle = "Welcome to ASA-GGC";
                        String mailbody = "Thank you for registering.<p> This is the confirmation email of your registration.<p>";
                        String sendmail = " Subject : " + mailtitle + " " + " <br><hr> " +  " " + mailbody + " " + " <hr> ";

                        // To create session, java.util.Properties class is created.
                        // SMTP host address is assigned
                        Properties props = new Properties();
                        props.put("mail.host", SMTP_HOST);

                        // Create and assign of default session
                        Session msgSession = Session.getDefaultInstance(props, null);

                        try {

                        // Create object of message class using session
                        MimeMessage msg = new MimeMessage(msgSession);
                        InternetAddress from = new InternetAddress(mailFrom);
                        msg.setFrom(from);

                        InternetAddress to = new InternetAddress(mailTo);
                        msg.setRecipient(Message.RecipientType.TO, to);

                        msg.setSubject(mailtitle);

                        msg.setContent(sendmail, "text/html; charset=EUC_KR"); // HTML Type

                        Transport.send(msg);

						// Show the message when the email sent successfully
                        out.println("The confirmation email of your registration was sent to "+mailTo+" successfully.<br />");
                        } 

						// Show the message when the email sent unsuccessfully
                        catch (AddressException mex){
                              out.println("The following email address has a problem:" +mailTo+"<br />");
                               } 

                        catch (SendFailedException mex) {
                              out.println("The following email address failed to send:" +mailTo+"<br />");
                               } 

                        catch (MessagingException mex) {
                              mex.printStackTrace();
                               } 
                %>
                <!-- END Welcome Email Module -->

                </div>
            </div>        
    </body>
</html>